﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project.MVC.Model;
using Project.MVC.MsSQLDAL;
namespace Project.MVC.Service
{
    public class ImageServices : IImageServices
    {
        IImageRepository repository = null;
        public ImageServices()
            : this(new ImageRepository())
        {
        }

        public ImageServices(IImageRepository rep)
        {
            repository = rep;
            if (repository == null)
                throw new InvalidOperationException("Repository cann't be null");
        }
        public IQueryable<ImageInfo> GetList2Grid()
        {
            return repository.GetList();
        }

        public List<ImageInfo> GetList()
        {
            return repository.GetList().ToList();
        }

        public List<ImageInfo> GetList(int start, int offset)
        {
            throw new NotImplementedException();
        }

        public ImageInfo GetByKey(int id)
        {
            return repository.GetList().Where(c => c.Id == id).SingleOrDefault();
        }
        public bool Insert(ImageInfo value)
        {
            return repository.Insert(value);
        }

        public bool Update(ImageInfo value)
        {
            return repository.Update(value);
        }

        public bool Delete(ImageInfo value)
        {
            return repository.Delete(value);
        }

        public void SaveChange()
        {
            repository.Commit();
        }

        public int Count()
        {
           return repository.Count();
        }
    }
}
